<?php
/**
 * @title 移位性能
 * @author start2004
 */


class Solution {

    /**
     * @title 整除2
     * @author start2004
     * @since 2020-07-24 Created
     *
     * @param int $N
     * @return int
     */
    function divisionTwo($N = 0){
        $N = $N/10;

        /**
         * @since 2020-07-24 N=100,000
         */
        for ($i=0; $i<=$N; $i++){
            /**
             * @since 2020-07-24 1050-1100ms
             */
            // $result = intval($i/2);

            /**
             * @since 2020-07-24 40-50ms
             */
            $result = $i>>1;
        }

        /**
         * @return
         */
        return $result;
    }

    /**
     * @param Integer $N
     * @return Boolean
     */
    function evenNumber($N = 0) {
        /**
         * @since 2020-07-24 N=1,000,000
         */
        for ($i=0; $i<=$N; $i++){
            // if($i%2 === 0){ // 390-400ms
            if($i === ($i>>1)<<1){ // 420-430ms
                $result = true;
            } else {
                $result = false;
            }
        }

        /**
         * @return
         */
        return $result;
    }

    /**
     * @title 10倍
     * @author start2004
     * @since 2020-07-24 Created
     *
     * @param int $N
     */
    function tenNumber($N = 0){
        /**
         * @since 2020-07-24 N=1,000,000
         */
        for ($i=0; $i<=$N; $i++){
            /**
             * @since 2020-07-24 4个时期周期, 285-295ms
             */
            // $result = $i*10;

            /**
             * @since 2020-07-24 3个机器周期, 340-350ms
             */
            $result = ($i<<3) + ($i<<1);
        }

        /**
         * @return
         */
        return $result;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.24_2.php
 */
$datas = [
    pow(10,6),
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->divisionTwo($data);
    // $result = $obj->evenNumber($data);
    // $result = $obj->tenNumber($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
